<? /* classes.php by Leslie */

class Application {	
	
	function load() {
		$this->db = new Database();
	}
}

class Database {
		
	function Database($host, $user, $password, $dbname) {
		mysql_connect($host, $user, $password);
		mysql_select_db($dbname);
	}
	
	function update($table, $condition, $data) {
		foreach($data as $key => $value) {
				if ($key == "form-action" || $key == "submit" || $key == "id") continue;
				$lines[] = $key . " = '" . $value . "'";
			}
			$lines = implode(", ", $lines);
			$query = "UPDATE $table SET $lines WHERE $condition";
			if (!mysql_query($query)) echo die(mysql_error());
	}
	
	function add($table, $data) {
		foreach($data as $key => $value) {
				if ($key == "form-action" || $key == "submit") continue;
				$keys[] = $key;
				$values[] = "'" . $value . "'";
			}
			$keys = implode(", ", $keys);
			$values = implode(", ", $values);
			$query = "INSERT INTO $table($keys) VALUES($values)";
			if (!mysql_query($query)) echo die(mysql_error());
			return mysql_insert_id();
	}
}

?>